package test;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;

import javax.sql.DataSource;

import com.alibaba.druid.pool.DruidDataSourceFactory;

public class DruidDemo {
    public static void main(String[] args) throws Exception {
        // 1.导入jar包
        // 2.定义配置文件
        // 3.加载配置文件
        Properties pro = new Properties();
        File file = new File("D:\\12.vscode-workspace\\rose-core\\resource\\database");
        InputStream is = new FileInputStream(new File(file, "druid.properties"));
        pro.load(is);
        // 4.获取连接池对象
        DataSource ds = DruidDataSourceFactory.createDataSource(pro);
        // 5.获取连接
        Connection conn = ds.getConnection();
        System.out.println(conn);
        Statement stmt = conn.createStatement();
        ResultSet set = stmt.executeQuery("select fieldid from ADMIN_FIELD order by fieldid");
        int count = 0;
        System.out.println("ok");
        while (set.next()) {
            System.out.println(set.getString("fieldId"));
            count++;
            if (count == 10) {
                break;
            }
        }
        is.close();
        conn.close();
    }
}
